package answer.service.Impl;

import answer.mapper.CollectionMapper;
import answer.service.CollectionService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import commons.pojo.Collection;
import commons.pojo.Love;
import commons.vo.LivegoodsResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CollectionServiceImpl implements CollectionService {
//    @Autowired
//    private ItemService itemService;
    @Autowired
    private CollectionMapper collectionMapper;
    @Override
    public List<Collection> selectCollection(int id) {
        QueryWrapper<Collection> collectionQueryWrapper = new QueryWrapper<>();
        collectionQueryWrapper.eq("user", id);
        List<Collection> collections = collectionMapper.selectList(collectionQueryWrapper);
        return collections;
    }

    @Override
    public LivegoodsResult saveCollection(Collection collection) {
        collectionMapper.insert(collection);
        return LivegoodsResult.ok("已收藏");
    }

    @Override
    public LivegoodsResult deleteCollection(int user, String item,int temp) {
        QueryWrapper<Collection> collectionQueryWrapper = new QueryWrapper<>();
        collectionQueryWrapper.eq("user", user);
        collectionQueryWrapper.eq("collection", item);
        collectionQueryWrapper.eq("category", temp);
        collectionMapper.delete(collectionQueryWrapper);
        return LivegoodsResult.ok("已删除");
    }
}
